package com.helloUIBinder.client.widgets;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;

public class FooterWidget extends Composite {

    private static FooterWidgetUiBinder uiBinder = GWT.create(FooterWidgetUiBinder.class);

    interface FooterWidgetUiBinder extends UiBinder<Widget, FooterWidget> {
    }

    @UiField
    Anchor homeLink;

    @UiField
    Anchor aboutLink;

    @UiField
    Anchor workLink;

    @UiField
    Anchor serviceLink;

    @UiField
    Anchor blogLink;

    @UiField
    Anchor contactLink;

    public FooterWidget() {
        initWidget(uiBinder.createAndBindUi(this));
    }

    private void changeBodyTo(Widget widget){
        BodyContainerWidget currentBodyContainerWidget = (BodyContainerWidget) RootPanel.get().getWidget(1);
        currentBodyContainerWidget.getBodyContainer().remove(0);
        currentBodyContainerWidget.getBodyContainer().add(widget);
    }

    @UiHandler("homeLink")
    void onHomeWidgetClick(ClickEvent event) {
        HomePageWidget homePageWidget = new HomePageWidget();

        changeBodyTo(homePageWidget);
    }

    @UiHandler("aboutLink")
    void onAboutWidgetClick(ClickEvent event) {
        AboutPageWidget aboutPageWidget = new AboutPageWidget();

        changeBodyTo(aboutPageWidget);
    }

    @UiHandler("workLink")
    void onWorkWidgetClick(ClickEvent event) {
        WorkWidget workWidget = new WorkWidget();

        changeBodyTo(workWidget);
    }

    @UiHandler("serviceLink")
    void onServiceWidgetClick(ClickEvent event) {
        ServicePageWidget servicePageWidget = new ServicePageWidget();

        changeBodyTo(servicePageWidget);
    }

    @UiHandler("blogLink")
    void onBlogWidgetClick(ClickEvent event) {
        BlogPageWidget blogPageWidget = new BlogPageWidget();

        changeBodyTo(blogPageWidget);
    }

    @UiHandler("contactLink")
    void onContactWidgetClick(ClickEvent event) {
        ContactPageWidget contactPageWidget = new ContactPageWidget();

        changeBodyTo(contactPageWidget);
    }
}
